package io.github.hellomaker.test;

import com.alibaba.fastjson.JSON;
import io.github.hellomaker.domain.strategy.service.armory.IStrategyArmory;
import io.github.hellomaker.domain.strategy.service.armory.IStrategyDispatch;
import io.github.hellomaker.infrastructure.dao.IAwardDao;
import io.github.hellomaker.infrastructure.dao.po.Award;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApiTest {

    @Resource
    IAwardDao iAwardDao;

    @Resource
    IStrategyArmory iStrategyArmory;

    @Resource
    IStrategyDispatch iStrategyDispatch;

    @Test
    public void test() {
        log.info("测试完成");
        List<Award> awards = iAwardDao.queryAwardList();

        log.info(JSON.toJSONString(awards));

    }


    @Test
    public void test1() {
        Long strategyId = 100001L;
        iStrategyArmory.assembleLotteryStrategy(strategyId);
        System.out.println("exit");
    }

    @Test
    public void test2() {
        Long strategyId = 100001L;
        for (int i = 0; i < 100000; i++) {
            Integer randomAwardId = iStrategyDispatch.getRandomAwardId(strategyId);
            System.out.println("randomAwardId:" + randomAwardId);
        }
    }

    @Test
    public void test3() {
        Long strategyId = 100001L;
        for (int i = 0; i < 1000; i++) {
            Integer randomAwardId = iStrategyDispatch.getRandomAwardId(strategyId, 60);
            System.out.println("rule weight 60, randomAwardId:" + randomAwardId);
        }
        for (int i = 0; i < 1000; i++) {
            Integer randomAwardId = iStrategyDispatch.getRandomAwardId(strategyId, 200);
            System.out.println("rule weight 200, randomAwardId:" + randomAwardId);
        }
        for (int i = 0; i < 1000; i++) {
            Integer randomAwardId = iStrategyDispatch.getRandomAwardId(strategyId, 1000);
            System.out.println("rule weight 1000, randomAwardId:" + randomAwardId);
        }
    }



}
